#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
	int m, n, tem;
	scanf("%d %d", &m, &n);

	while (n)  
	{
		tem = n;
		n = m % n;
		m = tem;  //辗转相除法
	}

	printf("%d", m);
	return 0;
}